﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Master.Dao;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.App.Search.Bean;
using Shpm.App.Commons.Utils;
using Shpm.App.Master.Bean;
using System.IO;

public partial class App_Input_RoomDetailsInfoForm : System.Web.UI.Page
{
    public string docApartmentNo = string.Empty ;
    public string docBuildingNo = string.Empty;
    public string docRoomNo = string.Empty;
    public string docRoomName = string.Empty;
    public string docRoomNote = string.Empty;
    public string docRoomPosition = string.Empty;
    public string docFloor = string.Empty;
    public string docCapacity = string.Empty;
    public string docStatusNo = string.Empty;
    public string docModel = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            SalesInfoBean dataBean = new SalesInfoBean();
            ViewState["STATUS_NO"] = Convert.ToString(Context.Items["STATUS_NO"]);
            ViewState["APARTMENT_NO"] = Convert.ToString(Context.Items["APARTMENT_NO"]);
            CheckImf(Convert.ToString(ViewState["APARTMENT_NO"]));

            // add by zhang 
            if (Context.Items.Contains("ParamCommand"))
            {
                ViewState["InpApartStatus"] = Convert.ToString(Context.Items["InpApartStatus"]);
                ViewState["InpBuildingNo"] = Convert.ToString(Context.Items["InpBuildingNo"]);
                ViewState["InpApartType"] = Convert.ToString(Context.Items["InpApartType"]);
                ViewState["InpApartId"] = Convert.ToString(Context.Items["InpApartId"]);
                ViewState["ParamPageIndex"] = Convert.ToString(Context.Items["ParamPageIndex"]);
                ViewState["ParamCommand"] = Convert.ToString(Context.Items["ParamCommand"]);
                ViewState["buildingNo"] = Convert.ToString(Context.Items["buildingNo"]);
            }
            // add by zhang 

            ViewState["ParamPageIndex"] = Convert.ToString(Context.Items["ParamPageIndex"]);
        }
    }
    #region 检查信息是否存在
    /*
     *名称： CheckImf
     *功能： 检查信息是否存在
     *参数： str
     *返回： 无
     *说明： 无
     */
    private void CheckImf(string str1)
    {
        MstApartmentBean dataBean = new MstApartmentBean();
        dataBean.ApartmentNo = str1;
        ApartmentDao Dao = new ApartmentDao();
        dataBean = Dao.Load(dataBean);
        if (dataBean != null)
        {
            SetRoomInf(dataBean);

            ApartmentDao dao = new ApartmentDao();
            ApartmentSchemeDetailBean paramBean = new ApartmentSchemeDetailBean();
            paramBean.SchemeId = dataBean.SchemeId;
            IList dataList = dao.FindByApartmentScheme(paramBean);
            GridView1.DataSource = dataList;
            GridView1.DataBind();
        }
        else
        {
        }
    }
    #endregion

    #region 显示信息
    /*
     *名称： SetRoomInf
     *功能： 显示信息
     *参数： dataBean
     *返回： 无
     *说明： 无
     */
    private void SetRoomInf(MstApartmentBean dataBean)
    {
        string str=string.Empty ;
        docApartmentNo = dataBean.ApartmentNo;
        docBuildingNo = dataBean.BuildingNo;
        docRoomNo = dataBean.RoomNo;
        docRoomName = dataBean.Name;
        docRoomNote = dataBean.Memo;
        docRoomPosition = dataBean.Location;
        docFloor = "第" + dataBean.Floor + "层";
        if (dataBean.Capacity > 0) docCapacity = dataBean.Capacity.ToString() + "人";
        docStatusNo = Convert.ToString(ViewState["STATUS_NO"]);
        docModel = dataBean.Content;
        if (dataBean.Model  != string.Empty)
        {
            str = dataBean.Model;
        }
        ChangeDIV(str);
    }
    #endregion

    #region 显示DIV
    /*
     *名称： ChangeDIV
     *功能： 显示DIV
     *参数： str
     *返回： 无
     *说明： 无
     */
    private void ChangeDIV(string str)
    {

        ((HtmlContainerControl)roomA).Style.Add("display", "");
        string strSrc = "../../Design/Room_" + str + ".htm";
        string fPath = Server.MapPath(strSrc);
        if (File.Exists(fPath))
            ((HtmlGenericControl)iRoom).Attributes.Add("src", strSrc);
        else
            ((HtmlContainerControl)roomA).Style.Add("display", "none");
    }
        #endregion

    // add by zhang 
    // 返回按钮
    protected void btnExit_Click(object sender, EventArgs e)
    {
        if (ViewState["ParamCommand"] != null)
        {
            Context.Items["InpApartStatus"] = ViewState["InpApartStatus"];
            Context.Items["InpBuildingNo"] = ViewState["InpBuildingNo"];
            Context.Items["InpApartType"] = ViewState["InpApartType"];
            Context.Items["InpApartId"] = ViewState["InpApartId"];
            Context.Items["ParamPageIndex"] = ViewState["ParamPageIndex"];
            Context.Items["ParamCommand"] = ViewState["ParamCommand"];
            Context.Items["buildingNo"] = ViewState["buildingNo"];
            // Server.Transfer("~/App/Input/RoomBookSrhForm.aspx", true);
            ControllerUtils.Transfer(this.Context, "~/App/Input/RoomBookSrhForm.aspx", true);
        }
        else 
        {
            Context.Items["ParamPageIndex"] = ViewState["ParamPageIndex"];
            // Server.Transfer("~/App/Search/RoomStatusSrhForm.aspx", true);
            ControllerUtils.Transfer(this.Context, "~/App/Search/RoomStatusSrhForm.aspx", true);
        }
    }
    // add by zhang 
}
